package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class Adapter3 extends RecyclerView.Adapter<Adapter3.MyViewHolder> {

    @NonNull
    @Override
    public Adapter3.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        inflater= LayoutInflater.from(context).inflate(R.layout.layout_item3,parent,false);
        return new MyViewHolder(inflater);
    }

    List<Map<String,Object>> list;

    View inflater;

    Context context;

    public Adapter3(Context context, List<Map<String,Object>> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.imageView1.setImageResource((Integer) Objects.requireNonNull(list.get(position).get("image")));
        holder.textView.setText(Objects.requireNonNull(list.get(position).get("item")).toString());
        holder.imageView2.setImageResource((Integer) Objects.requireNonNull(list.get(position).get("arrow")));

//        holder.imageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent=new Intent(context,MainActivity_detail2.class);
//                intent.putExtra("avatar", (Integer) Objects.requireNonNull(list.get(position).get("avatar")));
//                intent.putExtra("name", Objects.requireNonNull(list.get(position).get("username")).toString());
//                intent.putExtra("sex",Objects.requireNonNull(list.get(position).get("sex")).toString());
//                context.startActivity(intent);
//            }
//        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        ImageView imageView1,imageView2;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView1=itemView.findViewById(R.id.imageView_my_item);
            textView=itemView.findViewById(R.id.textView_my_item);
            imageView2=itemView.findViewById(R.id.imageView_my_arrow);
        }
    }
}
